//
//  PresentationObject.m
//  OnionHome
//
//  Created by fengjie on 2019/9/13.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PresentationObject.h"
#import "CustomPresentationVc.h"

@interface PresentationObject ()<UIViewControllerTransitioningDelegate>

@end

@implementation PresentationObject
SingletonM(PresentationObject);
/**
 弹出视图
 
 @param presentingViewController 跳转前的原控制器
 @param presentedViewController 将要跳转到的目标控制器
 */
-(void)showPresentingViewController:(UIViewController *)presentingViewController PresentedViewController:(UIViewController *)presentedViewController{
    presentedViewController.modalPresentationStyle = UIModalPresentationCustom;// 设置 动画样式
    presentedViewController.transitioningDelegate = self;// 此对象要实现 UIViewControllerTransitioningDelegate 协议
    [presentingViewController.navigationController presentViewController:presentedViewController animated:YES completion:nil];
    
    
}
#pragma mark - UIViewControllerTransitioningDelegate
// 返回控制控制器弹出动画的对象
/**
 *  参数: presentedViewController     将要跳转到的目标控制器
 presentingViewController    跳转前的原控制器
 */
- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{
    
    CustomPresentationVc * vc = [[CustomPresentationVc alloc] initWithPresentedViewController:presented presentingViewController:presenting];
    kWeakSelf(weakSelf);
    vc.canceBlock = ^{
        BlockSafeRun(weakSelf.cancelBlock);
    };
    return vc;
    
}



@end
